import 'package:casdon/modules/me/data/api/service_process_api.dart';
import 'package:casdon/modules/me/domain/usecase/service_process_usecase.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class ServiceProcessNotifier
    extends AutoDisposeFamilyAsyncNotifier<List<ActivityEntity>, String> {
  @override
  Future<List<ActivityEntity>> build(String arg) async {
    if (arg.isEmpty) return [];
    final usecase = ref.read(serviceProcessUsecaseProvider);
    final resp = await usecase.execute(arg);
    return resp.entities;
  }

  Future<void> refresh(String reqId) async {
    state = const AsyncLoading();
    state = await AsyncValue.guard(() async {
      final usecase = ref.read(serviceProcessUsecaseProvider);
      final resp = await usecase.execute(reqId);
      return resp.entities;
    });
  }
}

final serviceProcessNotifierProvider =
    AutoDisposeAsyncNotifierProviderFamily<ServiceProcessNotifier,
        List<ActivityEntity>, String>(
  () => ServiceProcessNotifier(),
);


